/*----------------------------------------\ | Return the first position of a word in the string; | | Note: this function will also check to see if the word is separated| | by some special characters other then the regular characters;| |-------------------------------------------| |--------------------------------------------------------------------| |---------------------------| | Inputs: | | var - the input string you want to check against; | | excerpt - the word you want to check; | |--------------------------------------| |--------------------------------------------------------------------| |---------------------------------------| | Usage: indexw(var,excerpt); | \----------------------------------------*/ %macro indexw(var,excerpt); /*---------------------------------------------\ | Copy Right: Duo Zhou; | | Created: 10-27-2002 10:14pm; | \---------------------------------------------*/ %if (%sysfunc(index(%nrbquote(&var), %nrbquote(&excerpt)))=1) %then %do; %if (%eval(%length(%nrbquote(&var))+1) = %eval(%sysfunc(index(%nrbquote(&var), %nrbquote(&excerpt))) + %length(%nrbquote(&excerpt)))) %then %sysfunc(index(%nrbquote(&var), %nrbquote(&excerpt))); %else %if (%eval(%length(%nrbquote(&var))+1) > %eval(%sysfunc(index(%nrbquote(&var), %nrbquote(&excerpt))) + %length(%nrbquote(&excerpt)))) %then %do; %if (%sysfunc(rxmatch(%sysfunc(rxparse($a|$d)), %nrbquote(%substr(%nrbquote(&var), %eval(%sysfunc(index(%nrbquote(&var), %nrbquote(&excerpt))) + %length(%nrbquote(&excerpt))), 1))))) %then 0; %else %sysfunc(index(%nrbquote(&var), %nrbquote(&excerpt))); %end; %else 0; %end; %else %if (%sysfunc(index(%nrbquote(&var), %nrbquote(&excerpt)))>1) %then %do; %if (%sysfunc(rxmatch(%sysfunc(rxparse($a|$d)), %nrbquote(%substr(%nrbquote(&var), %eval(%sysfunc(index(%nrbquote(&var), %nrbquote(&excerpt))) -1), 1))))) %then 0; %else %do; %if (%eval(%length(%nrbquote(&var))+1) = %eval(%sysfunc(index(%nrbquote(&var), %nrbquote(&excerpt))) + %length(%nrbquote(&excerpt)))) %then %sysfunc(index(%nrbquote(&var), %nrbquote(&excerpt))); %else %if (%eval(%length(%nrbquote(&var))+1) > %eval(%sysfunc(index(%nrbquote(&var), %nrbquote(&excerpt))) + %length(%nrbquote(&excerpt)))) %then %do; %if (%sysfunc(rxmatch(%sysfunc(rxparse($a|$d)), %nrbquote(%substr(%nrbquote(&var), %eval(%sysfunc(index(%nrbquote(&var), %nrbquote(&excerpt))) + %length(%nrbquote(&excerpt))), 1))))) %then 0; %else %sysfunc(index(%nrbquote(&var), %nrbquote(&excerpt))); %end; %else 0; %end; %end; %else 0; %mend indexw;